<#include "/generation-templates/directive/field-type.ftl"/>
<#include "/generation-templates/directive/field-comment.ftl"/>
package ${package};

import com.ilxqx.framework.system.form.SearchForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import ${basePackage}.entity.${table.getCamelName()};
import ${basePackage}.form.search.${table.getCamelName()}SearchForm;
import ${basePackage}.repository.${table.getCamelName()}Repository;
import ${basePackage}.service.${table.getCamelName()}Service;
<#list table.getFields() as field>
<#if field.getRules().match("enum")>
import ${field.getType().getName()};
</#if>
</#list>

/**
 * ${table.getComment()}服务实现类
 * @author venus
 */
@Service
public class ${table.getCamelName()}ServiceImpl extends AbstractSearchableServiceImpl<${table.getCamelName()}, ${primary.getType().getSimpleName()}, ${table.getCamelName()}SearchForm> implements ${table.getCamelName()}Service {

	private final ${table.getCamelName()}Repository ${table.getLowerCamelName()}Repository;

	@Autowired
	public ${table.getCamelName()}ServiceImpl(${table.getCamelName()}Repository ${table.getLowerCamelName()}Repository) {
		super(${table.getLowerCamelName()}Repository);
		this.${table.getLowerCamelName()}Repository = ${table.getLowerCamelName()}Repository;
	}

	/**
	 * 创建空的或者带有默认值的实体对象
	 *
	 * @return 实体对象
	 */
	@Override
	public ${table.getCamelName()} create() {
		return new ${table.getCamelName()}();
	}

	<#list table.getFields() as field>
	<#if field.getRules().match("unique")>
	/**
     * 判断${field.getComment()}是否存在
     *
     * @param ${field.getLowerCamelName()} ${field.getComment()}
     * @return bool
     */
	@Override
	<#if field.getRules().getRule("unique").getParam("method")?has_content>
	public ${table.getCamelName()} ${field.getRules().getRule("unique").getParam("method")}(String ${field.getLowerCamelName()}) {
		return this.${table.getLowerCamelName()}Repository.getBy${field.getCamelName()}(${field.getLowerCamelName()});
	}
	<#else>
	public ${table.getCamelName()} ${field.getLowerCamelName()}Exists(String ${field.getLowerCamelName()}) {
		return this.${table.getLowerCamelName()}Repository.getBy${field.getCamelName()}(${field.getLowerCamelName()});
	}
	</#if>

	</#if>
	</#list>
	<#if table.getRules().match("multiUnique")>
    /**
	 * 判断<#list table.getRules().getRule("multiUnique").getParam("fields")?split("-") as val>${val}<#sep>, </#list>确定的记录是否存在
	 *
     <#list table.getRules().getRule("multiUnique").getParam("fields")?split("-") as val>
     * @param ${val} <@fieldComment tableInfo = table name = val ; comment>${comment}</@fieldComment>
	 </#list>
	 * @return bool
	 */
    @Override
	<#if table.getRules().getRule("multiUnique").getParam("method")?has_content>
	public ${table.getCamelName()} ${table.getRules().getRule("multiUnique").getParam("method")}(<#list table.getRules().getRule("multiUnique").getParam("fields")?split("-") as val><@fieldType tableInfo = table name = val ; type>${type}</@fieldType> ${val}<#sep>, </#list>) {
		return this.${table.getLowerCamelName()}Repository.getBy<#list table.getRules().getRule("multiUnique").getParam("fields")?split("-") as val>${val?cap_first}<#sep>And</#list>(<#list table.getRules().getRule("multiUnique").getParam("fields")?split("-") as val>${val}<#sep>, </#list>);
	}
	<#else>
    public ${table.getCamelName()} <#list table.getRules().getRule("multiUnique").getParam("fields")?split("-") as val><#if val?is_first>${val}<#else>${val?cap_first}</#if><#sep>And</#list>Exists(<#list table.getRules().getRule("multiUnique").getParam("fields")?split("-") as val><@fieldType tableInfo = table name = val ; type>${type}</@fieldType> ${val}<#sep>, </#list>) {
		return this.${table.getLowerCamelName()}Repository.getBy<#list table.getRules().getRule("multiUnique").getParam("fields")?split("-") as val>${val?cap_first}<#sep>And</#list>(<#list table.getRules().getRule("multiUnique").getParam("fields")?split("-") as val>${val}<#sep>, </#list>);
	}
	</#if>

	</#if>
}
